package org.format;

import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;

public class FormatNumberDemo {
    public static void main(String[] args) {
        //格式货币 自动加货币符号 自动千位符 保留2位小数
        NumberFormat nf1 = NumberFormat.getCurrencyInstance();
        System.out.println(nf1.format(Long.MAX_VALUE));
        System.out.println(nf1.format(Math.random() * 1000));
        System.out.printf("%s元%n", nf1.format(20));

        NumberFormat nf2 = NumberFormat.getPercentInstance();
        System.out.println(nf2.format(.5));
        System.out.println(nf2.format(1));
        System.out.println(nf2.format(.5678));

        //禁止使用千分符
        nf2.setGroupingUsed(false);
        nf2.setMinimumFractionDigits(5);
        System.out.println(nf2.format(24242.5678));


    }
}
